#include <iostream>

using namespace std;

int a, f, ntest;

int main()
{
	//freopen("488.in", "r", stdin);
	//freopen("488.out", "w", stdout);

	cin >> ntest;
	while (ntest-- > 0)
	{
		cin >> a >> f;

		for (int i = 0; i < f; i++)
		{
			for (int j = 1; j <= a; j++)
			{
				for (int k = 1; k <= j; k++) cout << j;
				cout << endl;
			}
			for (int j = a-1; j >= 1; j--)
			{
				for (int k = 1; k <= j; k++) cout << j;
				cout << endl;
			}

			if (i == f-1 && ntest == 0);
			else cout << endl;
		}
	}
	return 0;
}
